package com.heatup.apt.management.service.channer.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.heatup.apt.common.constants.UserConstants;
import com.heatup.apt.common.dao.ChannerDetailedMapper;
import com.heatup.apt.management.service.channer.ChannerDetailedService;
import com.heatup.apt.model.channer.ChannerDetailed;

@Service
public class ChannerDetailedServiceImpl implements  ChannerDetailedService{
	private Logger logger = LoggerFactory.getLogger(ChannerDetailedServiceImpl.class); 
	@Autowired
	private ChannerDetailedMapper channerDetailedMapper;
	
	/**
	 * 渠道二维码明细分页查询
	 */
	@Override
	public Map<String, Object> queryChannerDetailedList(Map<String, Object> map) {
		
		Map<String, Object> objectMap = new HashMap<>();
		int pageCount = 10 ;
		int pageSum = 0;
		int pageNum = (Integer)map.get("pageNum");
		objectMap.put("pageNo", pageNum==0?1:pageNum);
		objectMap.put("pageNum",pageNum);
		if( pageNum > 1){
			pageNum = pageCount * (pageNum-1);
			map.put("pageNum", pageNum);
			map.put("pageCount", pageCount);
		}else{
			map.put("pageCount", pageCount);
			map.put("pageNum",pageNum==1?0:pageNum);
		}
		List<ChannerDetailed> list = channerDetailedMapper.queryChannerDetailedAll(map);
		map.put("pageNum", null);
		List<ChannerDetailed> listAll = channerDetailedMapper.queryChannerDetailedAll(map);
		int vipNum = 0 ;
		int userNum = 0 ;
		for(ChannerDetailed cd:listAll){
			// 因为生产上面有些数据是有问题的
			if(null != cd.getUserInfo() && cd.getUserInfo().getLevel() != null){
				if(cd.getUserInfo().getLevel() == UserConstants.UserLevel.vip.getIndex()){
					vipNum = vipNum + 1;
				}else{
					userNum = userNum + 1;
				}
			}
		}
		objectMap.put("channerDetailed",list);
		objectMap.put("pageSum",listAll.size());
		objectMap.put("channelId",map.get("channelId"));
		objectMap.put("userId",map.get("userId"));
		objectMap.put("pageNum",pageNum);
		objectMap.put("vipNum",vipNum);
		objectMap.put("userNum",userNum);
		// 分页
		
		return objectMap;
	}
	
}
